2. SEMI-AUTOMATED CREATION OF CINEMAGRAPHS 20
Each brush mode (Figure 2.2.2) has associated parameters that the user can control using
the scrollbars below each brush. FLOOD_XY (Equation 2.2.2), FLOOD_RGB (Equation
2.2.3), and FLOOD_RGBD (Equation 2.2.4) have a threshold which control the maxi-
mum Euclidean distance value accepted. This, in turn, determines how far away, based on
Euclidean distance, the pixels can be from the original pixels and still be selected.
The following is the code I implemented for the flood-fill tools FLOOD_RGB and
FLOOD_RGBD. The method isInCircle calculates the Euclidean distance between the
neighboring pixel and the user selected pixel. If the Euclidean distance value is less than
the threshold value the method returns true. This code can be used for both tools since
Equation 2.2.3 is the same as Equation 2.2.4 where the depth component is ignored in the
Euclidean distance calculation.
boolean[][] selectPixels(int x, int y, int sr, int sg,
int sb, float sd, float threshold):
ArrayList<int[]> waiting = new ArrayList<int[]>()
boolean[][] active = new boolean[IMAGE_WIDE][IMAGE_HEIGHT]
int[] startingPoint = new int[2]
startingPoint[0] = x
startingPoint[1] = y
waiting.add(startingPoint)
active[x][y] = true
while (!waiting.isEmpty ()):
int[] waiting_to_look = (int[])waiting.get(0)
x = waiting_to_look[0]
y = waiting_to_look[1]
if ((x+1) < IMAGE_WIDE && (x-1) >= 0):
if (isInCircle(x+1, y, sr, sg, sb, sd, threshold)
&& !(active[x+1][y])):
int[] point_to_add = new int[2]
point_to_add[0] = x+1
point_to_add[1] = y
waiting.add(point_to_add)
active[x+1][y] = true
if (isInCircle(x-1, y, sr, sg, sb, sd, threshold)
&& !(active[x-1][y])):